package com.clqteam.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.clqteam.dao.EmployeeLoginDao;
import com.clqteam.model.Employee;
import com.clqteam.util.JDBCutil;


public class EmployeeLoginDaoImpl implements EmployeeLoginDao{

	@Override
	public Employee getEmployeeAccountAndEmployeePsw(String name, String psw) {
		    Employee em=new Employee();
			StringBuffer sql=new StringBuffer();
			sql.append(" SELECT * FROM s_employee ");
			sql.append(" WHERE eAccount=? AND ePsw=?");
			Connection con=JDBCutil.getConnection();
			try {
				PreparedStatement pst=con.prepareStatement(sql.toString());
				pst.setString(1, name);
				pst.setString(2, psw);
				 ResultSet rs=pst.executeQuery();
				 if(rs.next()){
					 em.seteId(rs.getInt("eId"));
					 em.seteAccount(rs.getString("eAccount"));
					 em.setePsw(rs.getString("ePsw"));
					 em.seteName(rs.getString("eName"));
			         
				 }
				JDBCutil.closeJDBC(pst, con);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		 
		return em;
	}

	@Override
	public boolean insertLoginTime(String drTime, String drInfo, int eId,String eName) {
		boolean b=false;
		
		StringBuffer sql = new StringBuffer();
		sql.append(" INSERT INTO s_dailyreport (drTime,drInfo,eId,eName)");
		sql.append(" VALUES (?,?,?,?)");
		Connection con=JDBCutil.getConnection();
		try {
			PreparedStatement pst=con.prepareStatement(sql.toString());
			pst.setString(1, drTime);
			pst.setString(2,drInfo);
			pst.setInt(3, eId);
			pst.setString(4,eName);
			int i=pst.executeUpdate();
			if(i>0){
				b=true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return b;
		
	}

}
